package com.ruoyi.web.controller.system;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.LuckyNumber;
import com.ruoyi.system.dto.AddFriendDTO;
import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.dto.MemberPackageDTO;
import com.ruoyi.system.service.IAddFriendService;
import com.ruoyi.system.service.IMemberService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** 会员配置管理  */
@RestController
@RequestMapping("/system/member")
public class MemberController extends BaseController {
    @Autowired
    private IMemberService memberService;
    @Autowired
    private IAddFriendService addFriendService;

    /**
     * 新增会员配置
     */
    @ApiOperation(value = "新增会员配置")
    @PostMapping(value = "/addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody MemberPackageVo memberPackageVo)
    {
        return success(memberService.addOrUpdate(memberPackageVo));
    }

    /**
     * 会员配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MemberSearchVo searchVo)
    {
        startPage();
        List<MemberPackageDTO> dto =  memberService.getList(searchVo);
        // 获取准确的总数
        int total = memberService.countList(searchVo);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(dto);
        rspData.setTotal(total);

        return rspData;

    }


    /**
     * 会员配置列表
     */
    @GetMapping("/listByApp")
    @Anonymous
    public List<MemberPackageDTO> listByApp(MemberSearchVo searchVo)
    {
        return memberService.getList(searchVo);

    }

    /**
     * 会员配置列表详情
     */
    @GetMapping("/info/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(memberService.getInfo(id));
    }

    /**
     * 添加好员配置
     */
    @ApiOperation(value = "添加好员配置")
    @PostMapping(value = "/addOrUpdateByFriend")
    public AjaxResult addOrUpdateByFriend(@RequestBody AddFriendVo vo)
    {
        return success(addFriendService.addOrUpdateByFriend(vo));
    }

    /**
     * 添加好员权限列表
     */
    @ApiOperation(value = "查询添加好员列表")
    @GetMapping(value = "/getAddFriendList")
    public TableDataInfo getAddFriendList(AddFriendSearchVo vo)
    {
        startPage();
        List<AddFriendDTO> dto = addFriendService.getAddFriendList(vo);
        // 获取准确的总数
        int total = addFriendService.countList(vo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(dto);
        rspData.setTotal(total);
        return rspData;
    }

    /**
     * 添加好员配置
     */
    @ApiOperation(value = "添加好员配置")
    @GetMapping(value = "/addFriendCheck/{userId}")
    @Anonymous
    public AjaxResult addFriendCheck(@PathVariable String userId)
    {
        return success(addFriendService.addFriendCheck(userId));
    }

    /**
     * 查询靓号会员
     */
    @ApiOperation(value = "查询靓号会员")
    @GetMapping(value = "/getLuckyNumberList")
    public TableDataInfo getLuckyNumberList(LuckyNumberVo vo)
    {
        startPage();
        List<LuckyNumber> dto = memberService.getLuckyNumberList(vo);
        // 获取准确的总数
        int total = memberService.getLuckyNumberCount(vo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setMsg("查询成功");
        rspData.setRows(dto);
        rspData.setTotal(total);
        return rspData;
    }


}
